import {
  DisableRes,
  PageResult,
  VoucherGroup,
  putVoucherGroupDto,
  VoucherGroupGateway,
  disableVoucherGroupDto,
  VoucherGroupInterfaceWithPrimary,
  PutMutiRes,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { VoucherGroupSchema } from "@/river/voucher-core";

export class ViewVoucherGroup extends ViewBase<VoucherGroup> implements ViewBaseAction<VoucherGroup>, VoucherGroupInterfaceWithPrimary<{}> {
  private static instance: ViewVoucherGroup;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewVoucherGroup();
    }

    if (!this.instance) this.instance = new ViewVoucherGroup();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  getSchema(): VoucherGroup {
    return new VoucherGroupSchema();
  }

  async get() {
    this.pending();
    return this.$request.get<null, PageResult<VoucherGroup>>(VoucherGroupGateway.path);
  }

  async put() {
    this.pending();
    const dto = { schemaList: this.data.schemaList };
    return this.$request.put<putVoucherGroupDto, PutMutiRes<VoucherGroup>>(VoucherGroupGateway.path, dto);
  }

  async disable(dto: disableVoucherGroupDto) {
    this.pending();
    return this.$request.delete<disableVoucherGroupDto, DisableRes>(VoucherGroupGateway.path, dto);
  }
}
